package com.atguigu.controller;


import com.atguigu.entity.AlbumAttributeValue;
import com.atguigu.entity.AlbumInfo;
import com.atguigu.login.TingShuLogin;
import com.atguigu.mapper.AlbumInfoMapper;
import com.atguigu.mapper.AlbumStatMapper;
import com.atguigu.mapper.TrackInfoMapper;
import com.atguigu.query.AlbumInfoQuery;
import com.atguigu.result.RetVal;
import com.atguigu.service.AlbumAttributeValueService;
import com.atguigu.service.AlbumInfoService;
import com.atguigu.service.ListenService;
import com.atguigu.vo.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 一级分类表 前端控制器
 * </p>
 *
 * @author Joe
 * @since 2024-11-15
 */
@Tag(name = "听专辑管理")
@RestController
@RequestMapping("/api/album/progress")
public class ListenController {
   @Autowired
   private ListenService listenService;


    //TODO id问题
   //@TingShuLogin
    @Operation(summary = "最近播放")
    @GetMapping("getRecentlyPlay")
    public RetVal getRecentlyPlay(){
        Map<String, Object> retMap = listenService.getRecentlyPlay();
        return RetVal.ok(retMap);
    }

    @Operation(summary = "更新播放进度")
    @PostMapping("updatePlaySecond")
    public RetVal updatePlaySecond(@RequestBody UserListenProcessVo userListenProcessVo){
        listenService.updatePlaySecond(userListenProcessVo);
        return RetVal.ok();
    }
    @Operation(summary = "上次播放")
    @GetMapping("getLastPlaySecond/{trackId}")
    public RetVal getLastPlaySecond(@PathVariable Long trackId){
        BigDecimal second = listenService.getLastPlaySecond(trackId);
        return RetVal.ok(second);
    }

    @Autowired
    private TrackInfoMapper trackInfoMapper;
    @Operation(summary = "获取声音统计信息")
    @GetMapping("getTrackStatistics/{trackId}")
    public RetVal getTrackStatistics(@PathVariable Long trackId){
       TrackStatVo trackStatVo = trackInfoMapper.getTrackStatistics(trackId);
        return RetVal.ok(trackStatVo);
    }

    @Operation(summary = "点赞声音")
    @GetMapping("collectTrack/{trackId}")
    public RetVal collectTrack(@PathVariable Long trackId){
        boolean flag = listenService.collectTrack(trackId);
        return RetVal.ok(flag);
    }

    @Operation(summary = "收藏声音")
    @GetMapping("isCollect/{trackId}")
    public RetVal isCollect(@PathVariable Long trackId){
        boolean flag = listenService.isCollect(trackId);
        return RetVal.ok(flag);
    }

    @Operation(summary = "获取用户收藏列表")
    @GetMapping("getUserCollectByPage/{pageNum}/{pageSize}")
    public RetVal getUserCollectByPage(@PathVariable Integer pageNum,
                                       @PathVariable Integer pageSize){
        IPage<UserCollectVo> pageParam = listenService.getUserCollectByPage(pageNum,pageSize);
        return RetVal.ok(pageParam);
    }

    @Operation(summary = "获取声音播放历史列表")
    @GetMapping("getPlayHistoryTrackByPage/{pageNum}/{pageSize}")
    public RetVal getPlayHistoryTrackByPage(@PathVariable Integer pageNum,
                                       @PathVariable Integer pageSize){
        IPage pageParam = listenService.getPlayHistoryTrackByPage(pageNum,pageSize);
        return RetVal.ok(pageParam);
    }

}
